# -*- coding：utf-8 -*-
"""
@Time:2024-08-207:52
@Auth:泛彼泊舟
@File:atest_api.py
@IDE:PyCharm
@模块功能：xxx
"""
import re

import pytest
import requests

from common.request.requests_util import RequestUtil
from common.yaml.yaml_Util import write_yaml, read_testcase


class TestApi:
    @pytest.mark.parametrize("caseinfo", read_testcase("phpwind002.yamlj"))
    def test_phpwind(self,caseinfo):
        print(caseinfo)
        urls = caseinfo["request"]["url"]
        method = caseinfo["request"]["method"]
        print("url={}".format(urls))
        print("method={}".format(method))
        res =  RequestUtil().send_all_request(method=method, url=urls)
        # csrf_token = re.search("name="csrf_token" value="(.*?)" ", res.text)
        # csrf_token = re.search('name="csrf_token" value="(.*?)"', res.text)
        # data = {"csrf_token": csrf_token.group(1)}
        # write_yaml(data)
        # findll = re.findall("name='csrf_token' value='\(.*?\)'", res.text)
        # print(findll)
        assert "学校数据" in res.text

    # def test_login(self):
    #     url = "http://47.107.116.139/phpwind/index.php?m=u&c=login&a=dorun"
    #     data = {
    #         "username": "baili",
    #         "password": "baili123",
    #         "csrf_token": TestApi.csrf_token,
    #         "backurl": "http://47.107.116.139/phpwind/",
    #         "invite": ""
    #     }
    #     headress = {
    #         "Accept": "application/json, text/javascript, /; q=0.01",
    #         "X-Requested-With": "XMLHttpRequest"
    #     }
    #     res = TestApi.sess.request(method="post", url=url, data=data, headers=headress)
    #     print(res.json())
    #
    # def test_get_token(self):
    #     url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=appid&secret=secret"
    #     params = {
    #         "grant_type":"client_credential",
    #         "appid":"",
    #         "secret":""
    #     }
    #
    #     TestApi.sess.request(method="get")
